<template>
    <el-form :model="usersForm" status-icon :rules="rules" ref="usersForm"
             label-width="150px"
             style="margin-top: 10px;color: #1f2d3d">
        <el-form-item class="form-label" label="用户名" prop="userName">
            <el-col :span="19">
                <el-input v-model="usersForm.userName" placeholder="用户名"
                          maxlength="11" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="手机号" prop="phone">
            <el-col :span="19">
                <el-input v-model="usersForm.phone" placeholder="手机号"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="昵称" prop="nickName">
            <el-col :span="19">
                <el-input v-model="usersForm.nickName" placeholder="昵称"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="密码" prop="password">
            <el-col :span="19">
                <el-input v-model="usersForm.password" placeholder="密码"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item class="form-label" label="备注" prop="remark">
            <el-col :span="19">
                <el-input v-model="usersForm.remark" placeholder="备注"
                          maxlength="20" autocomplete="off"></el-input>
            </el-col>
        </el-form-item>
    </el-form>
</template>

<script>
    import qs from 'qs';

    export default {
        name: "NewNode",
        data() {
            return {
                usersForm: {
                    id: "",
                    userName: '',
                    phone: '',
                    nickName: '',
                    password: '',
                    remark: ''
                },
                rules: {
                    userName: [],
                    phone: [],
                    nickName: [],
                    password: [],
                    remark: []
                }
            }
        },
        props: {
            id: {
                type: Number,
                default: -1
            }
        },
        mounted() {
            if (this.id !== -1) {
                axios.post("/bjdzms/users/findById",
                    qs.stringify({
                        'id': this.id
                    })).then(res => {
                    this.usersForm = res.data;
                });
            }
        },
        methods: {
            to(path) {
                this.$router.push({name: path});
            },
            submitForm() {
                if (this.id !== -1) {
                    this.usersForm.id = this.id;
                    axios.post("/bjdzms/users/upd",
                        qs.stringify(this.usersForm)
                    ).then(res => {
                        this.$emit('updateData');
                    });
                } else {
                    axios.post("/bjdzms/users/add",
                        qs.stringify(this.usersForm)
                    ).then(res => {
                        this.$emit('updateData2');
                    });
                }
            }
        }
    }
</script>

<style>
    .el-upload-dragger {
        height: 40px !important;
    }
</style>

<style scoped>
    .el-header {
        background: #EBEBEB;
        color: #e5e9ef;
        font-size: 2em;
        line-height: 80px;
        border: 5px solid #EBEBEB;
    }

    .el-main {
        background: #fff;
    }

    .el-container {
        height: 100%;
    }

    .el-form-item {
        width: 610px;
    }
</style>
